﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Ebt.Mvvm;
using Ebt.Mvvm.Navigator;
using Windows.ApplicationModel.Search;
using Windows_8_MVVM.ViewModels.Pages;

namespace Windows_8_MVVM.ViewModels
{
    public class RootModel : PageModel
    {
        public RootModel()
        {
            Navigation = new Navigation();

            GoBackCommand = new RelayCommand(OnGoBack, () => Navigation.CanGoBack);
            GoHomeCommand = new RelayCommand(OnGoHome);
            SearchPaneShow = new RelayCommand(OnSearchPaneShow);

            HomePageModel = new HomePageModel(this);
            SearchPageModel = new SearchPageModel(this);
        }

        public Navigation Navigation { get; private set; }

        public HomePageModel HomePageModel { get; set; }
        public SearchPageModel SearchPageModel { get; set; }

        public ICommand GoBackCommand { get; private set; }
        public ICommand GoHomeCommand { get; private set; }
        public ICommand SearchPaneShow { get; private set; }

        public void OnGoBack()
        {
            Navigation.GoBack();
        }

        public void OnGoHome()
        {
            Navigation.GoToHomePage();
        }

        public void OnSearchPaneShow()
        {
            SearchPane.GetForCurrentView().Show();
        }

        readonly Random _random = new Random();
        public List<object> SearchData(string queryText)
        {
            var count = _random.Next(0, 15);
            return HomePageModel.ItemsList.Take(count).ToList();
        }
    }
}